package src.dual_pointers;

/**
 * @author starsea
 * @date 2024-08-21 14:55
 */

public class Test04 {
    public static void main(String[] args) {
        int[] arr={1,4,4};
        int c=minSubArrayLen(4,arr);

    }
    public static int minSubArrayLen(int target, int[] nums) {
        int n=nums.length;
        int sum=0;
        int c=0;
        for(int i=0;i<n;i++){c+=nums[i];}
        if(c<target){return 0;}
        int left=0;
        int right=0;
        int min=0x3f3f3f;
        while(left<=right)
        {
            if(sum>=target)
            {
                min=min>right-left?right-left:min;
                sum-=nums[left++];
            }
            else if( sum<target)
            {
                if(right>=n)
                {
                    break;
                }
                sum+=nums[right++];
            }
        }
        return min;

    }
}
